import 'dart:convert' as convert;
import 'package:crypto/crypto.dart' as crypto;
import 'package:convert/convert.dart' as convert;
import 'package:dio/dio.dart';
import 'package:suxuanapp/http/DioUtil.dart';
import 'package:suxuanapp/http/http_router.dart';

class Domain {
  static Domain domain = new Domain();
  var companyID = "1531437604";

  void getDomainByCompanyID() {
//   var url= HttpRouter.getFullLink(HttpRouter.COMPANY_DOMAIN,null,null);
    var url = HttpRouter.COMPANY_DOMAIN;
    var key = "app_code=" + companyID + HttpRouter.CONTACT_KEY;
//   url = "http://127.0.0.1:3721/post";
    key = generateMd5(key).toUpperCase();
    try {
  DioUtil.getInstance().request(
          url, //正常回调
          (data) {
            print(data);
            if(data is String){
              print("正确String返回${data }");
            }else{
              print("正确返回${data[0]}");
            }
          },
          errorCallBack: //错误回调
              (error) {
                print("错误返回$error");
              },
          headers: {"ACCESS-TOKEN": key, "token": 'formweb'},
          data: FormData.fromMap({"app_code": companyID }),
        queryParameters: {"urlb":"ddd"},
          options: Options(method: "PUT"));
    } catch (e) {
      print('请求结果异常$e');
    }
  }

// md5 加密
  String generateMd5(String data) {
    var content = new convert.Utf8Encoder().convert(data);
    var digest = crypto.md5.convert(content);
    // 这里其实就是 digest.toString()
    return convert.hex.encode(digest.bytes);
  }
}
